home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: Optimizing Const Strings
- Date: 3 Apr 1996 14:50:47 GMT
- Organization: Netcom
- Message-ID: <4ju387$96q@cloner2.ix.netcom.com>
- References: <3160B12A.41C67EA6@umich.edu>
- NNTP-Posting-Host: den-co11-06.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Wed Apr 03 6:50:47 AM PST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <3160B12A.41C67EA6@umich.edu>, jmayer@umich.edu says...
- >
- >If I have an include file with a bunch of strings
- >in it:
- >
- > typedef const char const * ConstStr;
- > ConstStr strA = "aaa";
- > ConstStr strB = "bbb";
- > ConstStr strC = "ccc";
- >
- >And a program that uses only ONE of the aforementioned
- >strings, all of the C-compilers I've tested (CSet++ and
- >GCC) compile all three of the const strings into my
- >program, even though only one of them was used.
- >
- >Is there any way I can define these strings so that the
- >linker will refuse to link an unused string?
-
- No tactic is guaranteed to work, since this is
- implementation-dependent. However, I would try:
-
- 1) If you don't need the strings outside the module,
- then declare them static and see if the compiler
- is smart enough to omit them.
-
- 2) If you might need the strings outside of the module,
- then put each string in a separate module, and place
- all of the modules in a library for linking. The
- linker *should* only pull in the required symbols.
- However, the string-per-module overhead may
- swamp any space savings you would otherwise have.
-
- 3) You can also put them in a data file/resource file, yes?
-
- john lilley
-
-